﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FirstFloor.Reversi.Controls
{
    /// <summary>
    /// Represents a control panel.
    /// </summary>
    public class ControlPanel
        : ControlBase
    {
        /// <summary>
        /// Occurs when the hints button is clicked
        /// </summary>
        public event EventHandler<EventArgs> HintsClick;
        /// <summary>
        /// Occurs when the restart button is clicked
        /// </summary>
        public event EventHandler<EventArgs> RestartClick;

        private Button btnHints;
        private Button btnRestart;
        private Rectangle border;
        private TextBlock textInfo;

        /// <summary>
        /// Initializes a new instance of the <see cref="ControlPanel"/> class.
        /// </summary>
        public ControlPanel()
        {
            this.border = (Rectangle)FindName("border");
            this.btnHints = (Button)FindName("btnHints");
            this.btnRestart = (Button)FindName("btnRestart");
            this.textInfo = (TextBlock)FindName("textInfo");

            this.btnHints.Click += new EventHandler<EventArgs>(btnHints_Click);
            this.btnRestart.Click += new EventHandler<EventArgs>(btnRestart_Click);
        }

        /// <summary>
        /// Gets or sets the hints text.
        /// </summary>
        /// <value>The hints text.</value>
        public string HintsText
        {
            get { return this.btnHints.Text; }
            set { this.btnHints.Text = value; }
        }

        /// <summary>
        /// Sets the info text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public void SetInfoText(string text)
        {
            this.textInfo.Text = text;
        }

        protected override void UpdateLayout()
        {
            this.border.Width = this.Width;

            double btnLeft = Width - this.btnHints.Width - 4;
            this.btnHints.SetValue<double>(Canvas.LeftProperty, btnLeft);
            this.btnRestart.SetValue<double>(Canvas.LeftProperty, btnLeft);

            this.textInfo.Width = btnLeft - 154;
        }

        /// <summary>
        /// The resource name containg the xaml used to initialize the actual object
        /// </summary>
        /// <value></value>
        protected override string XamlResourceName
        {
            get { return "FirstFloor.Reversi.Source.Controls.ControlPanel.xaml"; }
        }

        private void btnHints_Click(object sender, EventArgs e)
        {
            if (HintsClick != null) {
                HintsClick(this, EventArgs.Empty);
            }
        }

        private void btnRestart_Click(object sender, EventArgs e)
        {
            if (RestartClick != null) {
                RestartClick(this, EventArgs.Empty);
            }
        }
    }
}
